import { httpClient } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { AjaxResult } from '@/api/model';
import { PageRequest, PageData } from '@/utils/common/types';
import { DictEntryInputDto, DictEntryOutputDto } from './dict.data';

enum DictApi {
  ReadDictEntry = '/api/admin/dict/readdictentry',
  CreateDictEntry = '/api/admin/dict/createdictentry',
  UpdateDictEntry = '/api/admin/dict/updatedictentry',
  DeleteDictEntry = '/api/admin/dict/deletedictentry',
}

export function ReadDictEntry(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<DictEntryOutputDto>>(
    {
      url: DictApi.ReadDictEntry,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function CreateDictEntry(dtos: DictEntryInputDto[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: DictApi.CreateDictEntry,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function UpdateDictEntry(dtos: DictEntryInputDto[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: DictApi.UpdateDictEntry,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function DeleteDictEntry(ids: string[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: DictApi.DeleteDictEntry,
      params: ids,
    },
    {
      errorMessageMode: mode,
    },
  );
}
